﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using BiffenGUI.BiffenService;

namespace BiffenGUI.UserControls
{
    public partial class MovieList : UserControl
    {
        public List<Movie> Movies { get; set; }
        public MemberAddBookingCurrent CurrentMoviesUserControl { get; set; }

        public MovieList()
        {
            InitializeComponent();
        }

        public void BuildMovieList(List<Movie> movies)
        {
            BuildMovieList(movies, null);
        }

        public void BuildMovieList(List<Movie> movies, MemberAddBookingCurrent p)
        {
            Movies = movies;
            CurrentMoviesUserControl = p;

            this.Controls.Clear();

            int colNum = 2;
            int rowNum = (movies.Count / colNum) + 1;
            int x = 10;
            int y = 10;
            int width = 285 + 10;
            int height = 165 + 10;

            bool done = false;
            int i = 0;
            for (int row = 0; row < rowNum; row++)
            {
                for (int col = 0; col < colNum; col++)
                {
                    try
                    {
                        MovieDetails md = new MovieDetails();
                        md.Update(Movies[i++], p);
                        md.Location = new Point(x, y);
                        this.Controls.Add(md);
                        x += width;
                    }
                    catch
                    {
                        done = true;
                        break;
                    }
                }
                y += height;
                x = 10;

                if (done)
                    break;
            }
        }

        private void MovieList_Load(object sender, EventArgs e)
        {

        }
    }
}
